package dto;

// Generated May 6, 2011 4:19:20 PM by Hibernate Tools 3.3.0.GA

import org.hibernate.criterion.Order;
import SessionFactory.SessionFactoryUtil;
import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import static org.hibernate.criterion.Example.create;

/**
 * Home object for domain model class Themes.
 * @see dto.Themes
 * @author Hibernate Tools
 */
public class ThemesHome {

	private static final Log log = LogFactory.getLog(ThemesHome.class);

	private final SessionFactory sessionFactory = SessionFactoryUtil.getInstance();

	public void persist(Themes transientInstance) {
		log.debug("persisting Themes instance");
		try {
			sessionFactory.getCurrentSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(Themes instance) {
		log.debug("attaching dirty Themes instance");
		try {
			sessionFactory.getCurrentSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Themes instance) {
		log.debug("attaching clean Themes instance");
		try {
			sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(Themes persistentInstance) {
		log.debug("deleting Themes instance");
		try {
			sessionFactory.getCurrentSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Themes merge(Themes detachedInstance) {
		log.debug("merging Themes instance");
		try {
			Themes result = (Themes) sessionFactory.getCurrentSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public Themes findById(Integer id) {
		log.debug("getting Themes instance with id: " + id);
		try {
			Themes instance = (Themes) sessionFactory.getCurrentSession().get(
					"dto.Themes", id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<Themes> findByExample(Themes instance) {
		log.debug("finding Themes instance by example");
		try {
			List<Themes> results = (List<Themes>) sessionFactory
					.getCurrentSession().createCriteria("dto.Themes").add(
							create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
	
	
	//////////////////////////////////////////////////////////////////////////Admin/////////////////////////////////////////////////////////
	 public List getAllThemes() {
    	List results=sessionFactory.getCurrentSession().createCriteria(Themes.class).addOrder(Order.asc("themename")).list();
    	return results;
	}

    public void startNew() {
        sessionFactory.getCurrentSession().beginTransaction();
    }

    public void finish() {
        sessionFactory.getCurrentSession().close();
    }

    public boolean commitTrans() {
        boolean result = false;

        try {
            sessionFactory.getCurrentSession().getTransaction().commit();
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
            result = false;
        }

        return result;
    }
}
